﻿

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Gift.Model;
using Gift.DAL;


namespace WebSite.cn.service
{
    public partial class enjoymentLife : BasePage
    {
        DALGoods theGoods = new DALGoods();
        DALNews theNews = new DALNews();

        DALGoodsType theGoodsType = new DALGoodsType();




        StringBuilder _sbLeftBody01 = new StringBuilder();

        public StringBuilder SbLeftBody01
        {
            get { return _sbLeftBody01; }
        
        }

        StringBuilder _sbLeftBody02 = new StringBuilder();

        public StringBuilder SbLeftBody02
        {
            get { return _sbLeftBody02; }

        }

        StringBuilder _sbLeftBody03 = new StringBuilder();

        public StringBuilder SbLeftBody03
        {
            get { return _sbLeftBody03; }

        }

        StringBuilder _sbLeftBody04 = new StringBuilder();

        public StringBuilder SbLeftBody04
        {
            get { return _sbLeftBody04; }

        }

        StringBuilder _sbLeftBody05 = new StringBuilder();

        public StringBuilder SbLeftBody05
        {
            get { return _sbLeftBody05; }

        }

        string _goodsTitle01 = string.Empty;

        public string GoodsTitle01
        {
            get { return _goodsTitle01; }
          
        }

        string _goodsTitle02 = string.Empty;

        public string GoodsTitle02
        {
            get { return _goodsTitle02; }

        }

        string _goodsTitle03 = string.Empty;

        public string GoodsTitle03
        {
            get { return _goodsTitle03; }

        }

        string _goodsTitle04 = string.Empty;

        public string GoodsTitle04
        {
            get { return _goodsTitle04; }

        }

        string _goodsTitle05 = string.Empty;

        public string GoodsTitle05
        {
            get { return _goodsTitle05; }

        }


        StringBuilder _sGoodsHtml01 = new StringBuilder();

        public StringBuilder SGoodsHtml01
        {
            get { return _sGoodsHtml01; }
          
        }

        StringBuilder _sGoodsHtml02 = new StringBuilder();

        public StringBuilder SGoodsHtml02
        {
            get { return _sGoodsHtml02; }

        }

        StringBuilder _sGoodsHtml03 = new StringBuilder();

        public StringBuilder SGoodsHtml03
        {
            get { return _sGoodsHtml03; }

        }

        StringBuilder _sGoodsHtml04 = new StringBuilder();

        public StringBuilder SGoodsHtml04
        {
            get { return _sGoodsHtml04; }

        }

        StringBuilder _sGoodsHtml05 = new StringBuilder();

        public StringBuilder SGoodsHtml05
        {
            get { return _sGoodsHtml05; }

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.GetArticleList();
                this.WriterGoodsHtml();
            }
        }

        public void WriterGoodsHtml()
        {
            StringBuilder sGoodsHtml = new StringBuilder();

            DataTable dtTypeName = theGoodsType.GetList("  isnull(visible,0)=1 and parentId in (select typeId from tbGoodsType where typeName='悠享生活' and typedepth=1 )").Tables[0];

            DataTable dtGoods;
            int m = 1;
            foreach (DataRow dr in dtTypeName.Rows)
            {
              
                dtGoods = theGoods.GetList( string.Format( " isnull(visible,0)=1 and isnull(isSale,0)=1 and typeid in ({0})  order by clicks desc ", dr["typeId"].ToString())).Tables[0];

                string classColor = "";
                for (int i = 0; i < dtGoods.Rows.Count; i++)
                {
                    sGoodsHtml.Remove(0, sGoodsHtml.Length);
                    if (i == 0)
                    {
                        classColor = "card_01";
                    }
                    else if (i == 1)
                    {
                        classColor = "card_02";
                    }
                    else if (i == 2)
                    {
                        classColor = "card_03";
                    }

                    sGoodsHtml.AppendFormat("       <div class=\"card_list left {5}\"> "
                                           + "   <div class='pic' title='{3}'> <img src=\"/uploadfile/product/{0}\"  alt=\"{3}\" /></div> "
                                              + " <div class=\"right\"><div title='{3}'> {1}</div> "
                                              + "<div class=\"buttom_01\"><div class=\"buttom_points\">{4}福点</div> <div class=\"button_img\"><a href=\"{2}\" target='_blank'  > <img src=\"/cn/images/goods_exchange.png\"  alt=\"\" /></a></div></div>"

                                              + " </div> "
                                            + " </div> "
                                            , dtGoods.Rows[i]["smallPic"].ToString()
                                            , dtGoods.Rows[i]["goodsName"].ToString().Length > 10 ? dtGoods.Rows[i]["goodsName"].ToString().Substring(0, 10) + ".." : dtGoods.Rows[i]["goodsName"].ToString()
                                            , dtGoods.Rows[i]["detailUrl"].ToString() == "" ? "/cn/goodsDetail.html?gid=" + dtGoods.Rows[i]["goodsId"].ToString() : dtGoods.Rows[i]["detailUrl"].ToString()
                                            , dtGoods.Rows[i]["goodsName"].ToString()
                                            , dtGoods.Rows[i]["changePoints"].ToString()
                                            , classColor
                                            );


                    if (m == 1)
                    {

                        SGoodsHtml01.Append(sGoodsHtml);
                    }
                    else if (m == 2)
                    {

                        SGoodsHtml02.Append(sGoodsHtml);
                    }

                    else if (m == 3)
                    {

                        SGoodsHtml03.Append(sGoodsHtml);
                    }
                    else if (m == 4)
                    {

                        SGoodsHtml04.Append(sGoodsHtml);
                    }
                    else if (m == 5)
                    {

                        SGoodsHtml05.Append(sGoodsHtml);
                    }

                    if (i == 2) { break; }

                }
                if (m == 1)
                {
                    _goodsTitle01 = dr["typeName"].ToString();
                  
                }
                else if (m == 2)
                {
                    _goodsTitle02 = dr["typeName"].ToString();
                    
                }

                else if (m == 3)
                {
                    _goodsTitle03 = dr["typeName"].ToString();
                    
                }
                else if (m == 4)
                {
                    _goodsTitle04 = dr["typeName"].ToString();
                  
                }
                else if (m == 5)
                {
                    _goodsTitle05 = dr["typeName"].ToString();
                 
                    break;
                }
                
                m++;
            }

              

        }

        void  GetArticleList()
        {

            DataTable table = theNews.GetList(10, "typeid in(select typeId from tbNewsType where typeName='悠享生活') and visible=1 and isnew=1", "newsOrder asc, updatetime desc").Tables[0];
            if (table != null)
            {
                int iRowIndex = 0;
                foreach (DataRow row in table.Rows)
                {
                    if (iRowIndex < 5)
                    {
                        _sbLeftBody01.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span> </li>"
                                               ,  "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                                               , row["newsname"].ToString()
                                               , row["newsname"].ToString().Length > 15 ? fun.Left(row["newsname"].ToString(), 15) + ".." : row["newsname"].ToString()
                                               );
                    }
                    else
                    {
                        _sbLeftBody02.AppendFormat("<li><span> <a href=\"{0}\" target='_blank' title=\"{1}\">{2}</a></span></li>"
                                                , "/cn/news_01.aspx?tid=" + row["typeid"].ToString() + "&nid=" + row["newsid"].ToString()
                                                , row["newsname"].ToString()
                                                 , row["newsname"].ToString().Length > 15 ? fun.Left(row["newsname"].ToString(), 15) + ".." : row["newsname"].ToString()
                                                );
                    }
                    iRowIndex++;
                }
            }
          
          
        }



    }
}